﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RMS.Utils.MVP;
using RMS.Web.Shell.Presenter;
using RMS.Web.Shell.View;
using System.Web.Security;
using RMS.Utils.Navigator;

namespace RMS.Account
{
    public partial class Login : Page<LoginPresenter>, ILoginView
    {

        #region [ Events ]
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void txtPassword_InvalidUsernameOrPassword(object sender, ServerValidateEventArgs e)
        {
            e.IsValid = this.Presenter.EmployeeExists(txtUsername.Text, txtPass.Text);
        }

        public void txtPassword_NotActiveEmployee(object sender, ServerValidateEventArgs e)
        {
            if (txtRPassword.Text != "")
            {
                e.IsValid = this.Presenter.InsertNewPassword(txtUsername.Text, txtRPassword.Text);
            }
            else if (!this.Presenter.EmployeeIsNotActive(txtUsername.Text))
            {
                this.NewPassword.Visible = true;
                e.IsValid = false;
            }
            else
            {
                e.IsValid = true;
            }
        }

        protected void btnlogin_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
            }
        }
        #endregion

    }
}
